package com.aluem.mydataxwebexecutor.engine;


import com.aluem.mydataxwebexecutor.core.java.com.alibaba.datax.core.Engine;

public class EngineTest {
    /**
     * datax执行
     * @param args
     */
    public static void main(String[] args) {
        //public static String DATAX_HOME = System.getProperty("datax.home");
        System.setProperty("datax.home", "mydataxweb-executor/src/main/java/com/aluem/mydataxwebexecutor/core"); //
        System.out.println(getCurrentClasspath());

        String[] datxArgs = {"-job", getCurrentClasspath() + "/job/stream2stream.json", "-mode", "standalone", "-jobid", "-1"};
//        String[] datxArgs = {"-job", getCurrentClasspath() + "/job/oracle2mysql.json", "-mode", "standalone", "-jobid", "-1"};
        System.out.println(datxArgs[1]); // 从本地项目获取json文件

        try {
            Engine.entry(datxArgs);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取当前路径
     * @return
     */
    public static String getCurrentClasspath() {
        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
        String currentClasspath = classLoader.getResource("").getPath();
        // 当前操作系统
        String osName = System.getProperty("os.name");
        if (osName.startsWith("Windows")) {
            // 删除path中最前面的/
            currentClasspath = currentClasspath.substring(1);
        }
        return currentClasspath;
    }

}
